<?php
/**
 * Creater: 李青林
 * Date Time : 2018/8/21 13:44
 */

namespace App\Admin\Extensions;
use Encore\Admin\Admin;

class CheckRowEdit
{
    protected $id;
    protected $url;

    public function __construct($id,$url)
    {
        $this->id = $id;
        $this->url = $url;
    }

    protected function script()
    {
        return <<<SCRIPT
$('.grid-check-row').on('click', function () {
    console.log($(this).data('url'));
   var kill_id=$(this).data('id') ;
 $.ajax({
             type: "GET",
             url: $(this).data('url'),
             data: { kill_id:kill_id },
             dataType: "json",
             success: function(data){
                 location.reload();
             console.log(data)
             }
   })
    // Your code.
});
SCRIPT;
    }

    protected function render()
    {
        Admin::script($this->script());

        // return "<a class='btn btn-xs btn-success fa fa-check grid-check-row' data-id='{$this->id}' data-url='{$this->url}'></a>";
        return "<a class='btn btn-xs btn-success fa fa-times grid-check-row' data-id='{$this->id}' data-url='{$this->url}'></a>";
        //return "<a class='btn btn-xs btn-success fa fa-check grid-check-row' data-id='{$this->id}' data-url='{$this->url}'></a>";
    }

    public function __toString()
    {
        return $this->render();
    }
}